package com.xhsj.user.hr.userInfo.service;

import com.xhsj.user.hr.userInfo.entity.TbGlobalUserFile;
import com.xhsj.user.hr.userInfo.mapper.TbGlobalUserFileMapper;
import com.xhsj.user.hr.userInfo.query.UserDetailFileQuery;
import com.xhsj.user.hr.userInfo.service.TbGlobalUserFileService;
import com.xhsj.user.hr.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 用户_相关文件 服务实现类
 * </p>
 *
 * @author liuqinghua
 * @since Sep 8, 2020 2:04:00 PM
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
//@CacheConfig(cacheNames = "TbGlobalUserFile")
public class TbGlobalUserFileService extends BaseService<TbGlobalUserFileMapper, TbGlobalUserFile>{
    @Autowired
    private TbGlobalUserFileMapper dao;

	/**
	 * 保存
	 * @author liuqinghua
	 * @date Sep 8, 2020 2:04:00 PM
	 */
    @Override
    //@CacheEvict(cacheNames="TbGlobalUserFile", allEntries=true)
    public boolean save(TbGlobalUserFile entity) {
        return super.save(entity);
    }

	/**
	 * 通过id获取数据
	 * @author liuqinghua
	 * @date Sep 8, 2020 2:04:00 PM
	 */
    @Override
    //@Cacheable(key = "#id",sync = true)
    public TbGlobalUserFile getById(Serializable id) {
        return super.getById(id);
    }

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Sep 8, 2020 2:04:00 PM
	 */
    @Override
    //@CacheEvict(cacheNames="TbGlobalUserFile", allEntries=true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

	/**
	 * 批量删除数据
	 * @author liuqinghua
	 * @date Sep 8, 2020 2:04:00 PM
	 */
    //@CacheEvict(cacheNames="SysDict", allEntries=true)
    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }

	/**
	 * 分页查询数据
	 * @author liuqinghua
	 * @date Sep 8, 2020 2:04:00 PM
	 */
    //@Cacheable(key = "#data",sync = true)
    public IPage<TbGlobalUserFile> selectPage(Map<String,Object> data) {
        int currentPage=1;
        if (!Objects.isNull(data.get("page"))) {
            currentPage=(Integer) data.get("page");
        }
        int pageSize=20;
        if (!Objects.isNull(data.get("size"))) {
            pageSize=(Integer) data.get("size");
        }

        TbGlobalUserFile entity = JSON.parseObject(JSON.toJSONString(data), TbGlobalUserFile.class);
        Page<TbGlobalUserFile> page = new Page(currentPage,pageSize);
        QueryWrapper<TbGlobalUserFile> wrapper = new QueryWrapper(entity);
        return super.selectPage(page, wrapper);
    }

	/**
	 * 查询所有数据
	 * @author liuqinghua
	 * @date Sep 8, 2020 2:04:00 PM
	 */
    @Override
    //@Cacheable(value = "TbGlobalUserFile",sync = true)
    public List<TbGlobalUserFile> selectAll() {
        return super.selectAll();
    }


    /**
     * 获取用户相关的文件信息
     * @author liuqinghua
     * @date Sep 8, 2020 2:04:00 PM
     */
    public List<UserDetailFileQuery> getFileInfo(Long userId) {
    return dao.getFileInfo(userId);
    }

    /**
     * 用户相关文件
     * @author liuqinghua
     * @date Sep 8, 2020 2:04:00 PM
     */
    public int deleteDataByUserId(Long userId) {
      return dao.deleteDataByUserId(userId);
    }
}
